﻿using System;
using HigLabo.Net.Extensions;

namespace HigLabo.Net.WindowsLive
{
    /// <summary>
    /// 
    /// </summary>
    public class Photo : LiveObject, IFileObject
    {
        /// <summary>
        /// 
        /// </summary>
        public Int32 Size { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public Int32 CommentsCount { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public Boolean CommentsEnabled { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public Int32 TagsCount { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public Boolean TagsEnabled { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public String Picture { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public String Source { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public ImageCollection Images { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public String WhenTaken { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public Int32 Height { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public Int32 Width { get; set; }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="jsontext"></param>
        public Photo(String jsontext)
            : base(jsontext)
        {
            this.SetProperty(jsontext);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="jsontext"></param>
        private new void SetProperty(String jsontext)
        {
            var d = this.SetData(jsontext);
            this.Size = d.ToInt32("size") ?? 0;
            this.CommentsCount = d.ToInt32("comments_count") ?? 0;
            this.CommentsEnabled = d.ToBoolean("comments_enabled") ?? false;
            this.TagsCount = d.ToInt32("tags_count") ?? 0;
            this.TagsEnabled = d.ToBoolean("tags_enabled") ?? false;
            this.Picture = d.ToString("picture");
            this.Source = d.ToString("source");
            if (d.ContainsKey("images") == true)
            {
                this.Images = new ImageCollection(d.ToString("images"));
            }
            this.WhenTaken = d.ToString("when_taken");
            this.Height = d.ToInt32("height") ?? 0;
            this.Width = d.ToInt32("width") ?? 0;
        }
    }
}
